package com.oig.sys.base.dao;

import com.oig.sys.base.entity.TbCountryGroupMember;
import com.oig.sys.base.vo.CountryGroupMemberVo;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;

/**
@author wuxl
*/
public interface ITbCountryGroupMemberDao extends JpaRepository<TbCountryGroupMember, Integer> {

	@Query("select new com.oig.sys.base.vo.CountryGroupMemberVo(t.id, t.countryCode, c.applyCode, c.name) " +
			" from TbCountryGroupMember t inner join TbCountry c on c.code = t.countryCode" +
			" where t.groupId=:groupId and t.countryCode=:countryCode")
	CountryGroupMemberVo getByCountryCodeAndGroupId(@Param("countryCode")String countryCode, @Param("groupId")Integer groupId);


	@Query("from TbCountryGroupMember t where t.groupId=:groupId and t.id not in(:idList)")
	List<TbCountryGroupMember> findByGroupIdAndIdNotIN(@Param("groupId") Integer groupId, @Param("idList") List<Integer> idList);


	@Query("select new com.oig.sys.base.vo.CountryGroupMemberVo(t.id, t.countryCode, c.applyCode, c.name)" +
			" from TbCountryGroupMember t inner join TbCountry c on c.code = t.countryCode " +
			" where t.groupId=:groupId")
	List<CountryGroupMemberVo> getGroupMemberByGroupId(@Param("groupId") Integer groupId);



}
